/* 
redux的核心者 store
内部存储state, 引用reducer
*/
import { createStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import { composeWithDevTools } from "redux-devtools-extension";
import rootReducer from "./reducers";
import { SearchState, CounterState } from "./reducers/types";

// 创建store, 指定reducer函数, 应用上redux的异步中间件, 启用redux调试工具
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)));

/* 约束根state对象的接口 */
export interface RootState {
  counter: CounterState;
  search: SearchState;
}
/* 
{
  counter: {
    count: 0
  },
  search: {
    firstView: true,
    loading: false,
    errMsg: '',
    users: []
  }
}
*/

export default store;
